<?php



namespace app\home\model;

use think\Cookie;

use think\Model;

use think\Db;
use think\Session;


class MemberModel extends Model

{



    //需要重新写

    protected $name = 'member';

    protected $autoWriteTimestamp = true;





    /**

     * vaildateUser [ 登录密码代码 ]

     * @author [Boot.Z] [852952656@qq.com]

     */

    public function vaildateUser($param,$from_cookie = false)
    {
        if($from_cookie){
            $data['password'] = $param['password'];
            $data['id'] = $param['id'];
        }else{
            $data['account'] = $param['username'];
            $data['password'] = md5(md5($param['password']));
        }
        $user = $this->where($data)->find();
        if($param['remember'] == 1){
            Cookie::set('daguan_nickname',$user['nickname'],3600);
            Cookie::set('daguan_u_id',$user['id'],3600);
            Cookie::set('daguan_password',$data['password'],3600);
        }
        Session::set('daguan_nickname',$user['nickname']);
        Session::set('daguan_u_id',$user['id']);

        if ($user){
            $user->save(['update_time'=>time(),['id'=>$user['id']]]);
            return ['code' => 1, 'url'=>url('home/member/index')];
        }else{
            return ['code' => 2, 'msg'=>'账号或密码不正确'];
        }

    }



}